package com.aliengen.thingple.driverapp.ui.fragments;

import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;

/**
 * This class is part of the Thingple mobile application for the CMC168 Handheld reader.
 *
 * Copyright AlienGen Limited 2016. All rights reserved.
 *
 * @author Timothé Mermet-Buffet <tim@aliengen.com>
 */
public class YesNoDialogFragment extends DialogFragment {
    public YesNoDialogFragment() {
        this.response = new Response() {
            @Override
            public void onConfirm() {

            }

            @Override
            public void onCancel() {

            }
        };
    }

    protected Response response;

    public void setResponse(Response response)
    {
        this.response = response;
    }

    @Override
    public Dialog onCreateDialog(Bundle savedInstanceState) {
        Bundle args = getArguments();
        String title = args.getString("title", "");
        String message = args.getString("message", "");

        return new AlertDialog.Builder(getActivity())
                .setTitle(title)
                .setMessage(message)
                .setPositiveButton(android.R.string.yes, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK, null);
                        response.onConfirm();
                    }
                })
                .setNegativeButton(android.R.string.no, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        //getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_CANCELED, null);
                        response.onCancel();
                    }
                })
                .create();
    }

    public interface Response {
        public void onConfirm();
        public void onCancel();
    }
}
